use crate::error::Result;
use bcrypt::{hash, verify, DEFAULT_COST};
use md5::{Digest, Md5};

pub fn hash_password(password: &str) -> Result<String> {
    let hashed = hash(password, DEFAULT_COST)?;
    Ok(hashed)
}

pub fn verify_password(password: &str, hash: &str) -> Result<bool> {
    let is_valid = verify(password, hash)?;
    Ok(is_valid)
}

pub fn calculate_file_hash(data: &[u8]) -> Result<String> {
    let mut hasher = Md5::new();
    hasher.update(data);
    let result = hasher.finalize();
    Ok(format!("{:x}", result))
}
